<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>回调函数</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }
    </style>
</head>
<body>
    
    <script type="text/javascript">
        // 回调函数：在某个操作执行之后调用的函数
        // box.onclick = function (){
            
        // }

        setTimeout(function (){
            console.log("1s 之后执行的函数");
        }, 1000);



        function sum(a, b, callback){
            // console.log(a + b);
            var c = a + b;
            // if(callback){
            //     callback(c);
            // }else {
            //     console.log(c);
            // }
            callback ? callback(c) : console.log(c);
            // callback && callback(c);
        }

        sum(2,3); // 5
        sum(2,3, function (a){
            console.log(a * 2);
        }); // 10
        sum(2,3, function (a){
            console.log(a / 2);
        }); // 2.5
        
    </script>
</body>
</html>